ActiveReports 10
Parameterized Reports
ActiveReports 10 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Page Report/RDL Report Walkthroughs > Preview > Parameterized Reports

You can create a parameterized report with ActiveReports and provide an "All" choice for users who want to see all of the data as well as the ability to select multiple values for those who want to see data for several items.

This walkthrough illustrates how to create a report with multivalue parameters and an option to select all of the data.

The walkthrough is split up into the following activities:

Note:

When you complete this walkthrough you get a layout that looks similar to the following at design time and at runtime.

Design Time Layout

Runtime Layout

To add an ActiveReport to the Visual Studio project

  1. Create a new Visual Studio project.
  2. From the Project menu, select Add New Item.
  3. In the Add New Item dialog that appears, select ActiveReports 10 Page Report and in the Name field, rename the file as MoviesByProducer.
  4. Click the Add button to open a new fixed page report in the designer.

See Adding an ActiveReport to a Project for information on adding different report layouts.

To connect the report to a data source

  1. In the Report Explorer, right-click the Data Sources node and select the Add Data Source option or select Data Source from the Add button.
  2. In the Report Data Source Dialog that appears, select the General page and in the Name field, enter a name like ReportData.
  3. On this page, create a connection to the Reels database. See Connect to a Data Source for information on connecting to a data source.

To add a dataset to populate the parameter values

  1. In the Report Explorer, right-click the data source node and select the Add Data Set option.
  2. In the DataSet Dialog that appears, select the General page and enter the name of the dataset as Producers. This name appears as a child node to the data source icon in the Report Explorer.
  3. On the Query page of this dialog, in the Query field enter the following SQL query.
    SQL Query
    Copy Code
    SELECT -1 AS ProductionID, "(All)" AS Name
    FROM Producers
    UNION
    SELECT ProductionID, Name
    FROM Producers;
    
  4. Click the Validate DataSet icon at the top right hand corner above the Query box to validate the query.

  5. Click OK to close the dialog. Your data set and queried fields appear as nodes in the Report Explorer.

To add a parameter to the report

  1. In the Report Explorer, select the Parameters node.
  2. Right-click the node and select Add Parameter to open the Report - Parameters dialog.
  3. In the dialog box that appears, click the Add(+) button to add a new parameter in the list.
  4. Set properties in the following fields below the parameters list.

    In the General tab:

    • Name: ProductionID
    • DataType: Integer
    • Text for prompting users for a value: Select a production company.
    • Select the check box next to Multivalue to allow users to select more than one production company from the list.

    In the Available Values tab select From query:

    • DataSet: Producers
    • Value: ProductionID
    • Label: Name
      Note: The name of the parameter you enter must exactly match the name of the parameter in the linked report, and it is case sensitive. You can pass a value from the current report to the parameter in the Value column of the list. If a value is not supplied for an expected parameter in the linked report, or if the parameter names do not match, the linked report will not run.
  5. Click OK to close the dialog and add the parameter to the collection. This parameter appears under the Parameters node in the Report Explorer.

To add a dataset with a parameter

  1. In the Report Explorer, right-click the data source node and select the Add Data Set option.
  2. In the DataSet Dialog that appears, select the General page and enter the name of the dataset as Movies. This name appears as a child node to the data source icon in the Report Explorer.
  3. On the Parameters page under Parameter Name enter Param1.
  4. Under Value enter =Parameters!ProductionID.Value
  5. On the Parameters page under Parameter Name enter Param2.
  6. Under Value enter =Parameters!ProductionID.Value
  7. On the Query page of this dialog, in the Query field enter the following SQL query.
    SQL Query
    Copy Code
    SELECT Movie.Title, Movie.YearReleased, Movie.UserRating, Producers.Name
    FROM Producers INNER JOIN (Movie INNER JOIN MovieProducers ON Movie.MovieID = MovieProducers.MovieID) ON Producers.ProductionID = MovieProducers.ProductionID
    WHERE (MovieProducers.ProductionID IN (?)) OR (-1 IN (?))
    ORDER BY MovieProducers.ProductionID, Movie.YearReleased;                                   
    
  8. Click the Validate DataSet icon at the top right hand corner above the Query box to validate the query.

  9. Click OK to close the dialog. Your data set and queried fields appear as nodes in the Report Explorer.

To create a layout for the report

  1. From the toolbox, drag a Table control onto the design surface and in the Properties window, set the following properties.
    Property Name Property Value
    Location 0in, 1in
    DataSetName Movies
    FixedSize (only for Page reports) 6.5in, 7.5in
  2. Click inside the table to display the column and row handles along the top and left sides of the table.
  3. To visually group the data within the report, right-click the icon to the left of the detail row and select Insert Group. 
  4. In the Table - Groups dialog that appears, under Expression select =Fields!Name.Value to group all details from each producer.
  5. Change the Name to Producer.
    Note: You cannot change the name of a table group until after you have set the expression.
  6. On the Layout tab of the Table - Groups dialog, select the check box next to Repeat group header to ensure that the header is printed at the top of each page.
  7. Clear the check box next to Include group footer as we will not be using it for this report.
  8. Click OK to close the dialog.
  9. In the Report Explorer, from the Movies dataset drag the following fields into the detail row of the table and set their properties as in the following table.
    Field Column Width
    Title TableColumn1 3.9in
    YearReleased TableColumn2 1.3in
    UserRating TableColumn3 1.3in
  10. Static labels with the field names are automatically created in the table header row. To improve the appearance of the report, select the table header row, and set the text to Bold and change the FontSize to 11pt.
  11. From the Report Explorer, the Movies dataset drag the Name field into the first column of the group header row of the table and set the following properties. 
    Property Name Property Value
    FontWeight Bold
    BackgroundColor Thistle
    Tip: Use the Ctrl key to select all three text boxes in the group header row, right-click and select Merge Cells to prevent long production company names from wrapping.

To view the report

OR